<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>专家人工服务管理</title>
	<meta name="decorator" content="default"/>
	<style type="text/css">
		#customer .ui-input-text{
			padding: 0.4em;
			display:inline-block;
			width: 10em;
		}
		#customer .ui-btn{
			padding: 0.4em;
			display:inline-block;
		}
	</style>
</head>
<body>
	<form:form id="inputForm" modelAttribute="expertManualService" class="form-input" action="${ctx}/expert/expertManualService/save" method="post">
		<form:hidden path="id"/>
		<form:hidden path="store.id" value="${fns:getStore().id}"/>
		<div class="icon-buttons">
			<a id="returnBtn" href="${ctx}/expert/expertManualService/"  data-icon="back" data-iconpos="notext" data-role="button" data-inline="true">返回</a>
			<input id="btnSubmit" data-icon="check" data-iconpos="notext" type="submit" value="保 存" data-inline="true"/>
		</div>
		<tags:message content="${message}"/>
		<div data-role="fieldcontain" id="customer">
			<label for="customerName">客户:</label>
			<input id="customerName" name="customerName" readonly="readonly" type="text" data-inline="true" value="">&nbsp;&nbsp;&nbsp;
			<input type="button" data-inline="true" onclick="selectCustomer()" value="选择客户">
			<input id="customerDetail" type="button" disabled="disabled" data-inline="true" onclick="showCustomerDetail()" value="查看客户详细资料">
			<form:hidden id="cid" path="customer.id"/>
		</div>
		<div data-role="fieldcontain">
			<label for="employee.id">店员:</label>
			<form:select id="employeeId" path="employee.id" data-native-menu="false" items="${fns:getEmployee()}"></form:select>
		</div>
		<div data-role="fieldcontain">
			<label for="question">请求问题:</label>
			<textarea id="question" name="question">
				${expertManualService.question}
			</textarea>
		</div>
	</form:form>
	<script type="text/javascript">
		$(document).ready(function() {
			$("#answer").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					var customer = $("#cid").val();
					if (!customer) {
						showTip("请选择客户");
						return;
					}
					var question = $("#question").val();
					question = question.replace(/[\r\n]/g,"").replace(/^\s*/g,"");
					
					if (!question) {
						showTip("请添加需要分析的问题描述");
						return;
					}
					$("#question").val(question);
					clear();
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			init();
			$("#returnBtn").click(function(){
				clear();
			});
		});
		function selectCustomer(){
			var fun = function(obj){
				$("#cid").val(obj.id);
				$("#customerName").val($(obj).attr("name"));
				if ($("#cid").val()){
					$("#customerDetail").button('enable'); 
					$("#customerDetail").button('refresh'); 
				}
			};
			var existId = $("#cid").val();
			global.singleSelectDialog("${ctx}/base/customer/customerData", "选择客户", existId ,fun);
		}
		function init(){
			if (sessionStorage.customerId){
				$("#cid").val(sessionStorage.customerId);
				$("#customerName").val(sessionStorage.customerName);
				$("#customerDetail").button('enable'); 
				$("#customerDetail").button('refresh'); 
			}
			if (sessionStorage.employeeId) {
				$("#employeeId").attr("value", sessionStorage.employeeId);
				$("#employeeId").selectmenu("refresh");

			}
			if (sessionStorage.question) {
				$("#question").val(sessionStorage.question);
			}
		}
		function clear(){
			sessionStorage.removeItem("customerId");
			sessionStorage.removeItem("customerName");
			sessionStorage.removeItem("employeeId");
			sessionStorage.removeItem("question");
		}
		function showCustomerDetail(){
			sessionStorage.target = "detailForm";
			sessionStorage.customerId = $("#cid").val();
			sessionStorage.customerName = $("#customerName").val();
			sessionStorage.employeeId = $("#employeeId").val();
			sessionStorage.question = $("#question").val();
			var cid = $("#cid").val();
			var url = "${ctx}/base/customer/detail?id=" + cid;
			window.location.href = url;
		}
	</script>
</body>
</html>
